package com.rran.study.designpattern.behavioral.template;


import com.rran.study.designpattern.behavioral.template.enums.ShoppingPersonEnum;
import com.rran.study.designpattern.behavioral.template.factory.ShoppingSpringFactory;
import com.rran.study.designpattern.behavioral.template.service.Shopping;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * 基于spring的策略+模板模式
 */
@EnableAutoConfiguration
public class SpringTemplateApplication {

    public static void main(String[] args) {

        //非web方式启动
        ConfigurableApplicationContext context = new SpringApplicationBuilder(SpringTemplateApplication.class)
                .web(WebApplicationType.NONE)
                .run(args);


        String beanNameA = ShoppingPersonEnum.getBeanNameByType("PERSON_A");
        String beanNameB = ShoppingPersonEnum.getBeanNameByType("PERSON_B");
        String beanNameC = ShoppingPersonEnum.getBeanNameByType("PERSON_C");
        Shopping personA = ShoppingSpringFactory.getShopping(beanNameA);
        Shopping personB = ShoppingSpringFactory.getShopping(beanNameB);
        Shopping personC = ShoppingSpringFactory.getShopping(beanNameC);


        System.out.println("A开始shopping");
        personA.buyGoods();
        System.out.println("===================");

        System.out.println("A开始shopping");
        personB.buyGoods();
        System.out.println("===================");

        System.out.println("B开始shopping");
        personC.buyGoods();
        System.out.println("===================");


        context.close();
    }


}
